﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using MemberShip.Imagine.Models.ViewModel;
using TVXD23.Web.Models;
using TVXD23.Web.Models.Helpers;
using TVXD23.Web.Models.ViewModel;

namespace TVXD23.Web.Controllers
{
    [Authorize(Roles = "Super Admin,Nhân viên,Admin")]

    public class AdminController : Controller
    {
        private cmsRepository _repository = new cmsRepository();
        public IMGRepository Repository = new IMGRepository();

        //Super Admin
        public ActionResult Index(string message)
        {
            AdminIndexViewModel model = new AdminIndexViewModel();
            if (String.IsNullOrEmpty(message))
                model.Message = "Thông báo : Trang chủ quản trị các tin bài";
            else
            {
                model.Message = message;
            }
            model.PressCategories = _repository.PressCategories();
            model.Presses = _repository.NewestPress(10);
            model.Presses_TranslatedCopy = _repository.NewestPress_TranslatedCopy(10);
            return View("~/Views/Admin/Index.aspx", model);
        }
        //
        // GET: /Admin
        public IFormsAuthenticationService FormsService { get; set; }
        public IMembershipService MembershipService { get; set; }

        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
            if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

            base.Initialize(requestContext);
        }
        #region Quan tri danh muc
        public ActionResult ViewPressCategoriesDetails(int pressCategoryId, int? currentPage)
        {
            PressViewModel model = new PressViewModel();

            var sq = _repository.GetPressCategory(pressCategoryId);
            model.TotalItem = sq.Presses.Count;
            model.PressCategoryId = pressCategoryId;
            model.PressCategoryList = _repository.PressCategories();
            model.PressCategoryName = sq.Title;
            if (currentPage.HasValue)
            {
                model.PressList = _repository.PressesByCategory(currentPage.Value - 1, sq.PressCategoryId);
                model.CurrentPage = currentPage.Value;
                model.Press_TranslatedCopyList = new List<Press_TranslatedCopy>();
                foreach (var item in model.PressList)
                {
                    var m = _repository.GetPressTranslated(item.PressId);
                    if(m!=null)
                    model.Press_TranslatedCopyList.Add(m);
                }
            }
            else
            {
                model.PressList = _repository.PressesByCategory(0, sq.PressCategoryId);
                model.CurrentPage = 1;
                model.Press_TranslatedCopyList = new List<Press_TranslatedCopy>();
                foreach (var item in model.PressList)
                {
                    var kq = _repository.GetPressTranslatedByPressId(item.PressId);
                    if (kq != null)
                        model.Press_TranslatedCopyList.Add(kq);
                }

            }
            return View("~/Views/Admin/Press/ViewPressCategoryDetails.aspx", model);


        }
        [Authorize(Roles = "Admin")]
        public ActionResult CreatePressCategory()
        {
            PressCategoryCpo model = new PressCategoryCpo();
            return View("~/Views/Admin/PressCategory/Create.aspx", model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult CreatePressCategory(PressCategoryCpo model)
        {
            if (ModelState.IsValid)
            {
                var m = new PressCategory();
                m.Description = model.Description;
                m.Title = model.Title;
                _repository.AddPressCategory(m);
                return RedirectToAction("Index", new { message = "Đã tạo xong bài viết " + model.Title });
            }
            else
            {
                return View("~/Views/Admin/PressCategory/Create.aspx", model);
            }
        }
        //public ActionResult DeletePressCategoy(int PressCategoryId)
        //{
        //    _repository.DelPressCategory(PressCategoryId);
        //    return RedirectToAction("Index", new { message = "Đã xóa danh muc" });
        //}
        #endregion
        #region Quan tri bai viet website
        public ActionResult CreatePress()
        {
            var model = new PressCpo();
            model.PressCategories = _repository.PressCategories();
            return View("~/Views/Admin/Press/Create.aspx", model);

        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult CreatePress(PressCpo model)
        {
            if (ModelState.IsValid)
            {
                string name = model.Title;
                name = name.Replace("?", "");
                name = name.Replace(".", "");
                name = name.Replace("/", "");
                name = name.Replace("\\", "");
                name = name.Replace("*", "");
                name = name.Replace("&", " và ");
                name = name.Replace("+", "-");
                name = name.Replace(":", "");
                name = name.Replace(";", "");
                name = name.Replace("=", "");
                Press press = new Press();
                press.Title = name;
                
                press.Body = model.Body;
                if(model.Description!=null)
                press.Description = model.Description;
                else
                {
                    press.Description = "";
                }
                press.ImagePath = model.ImagePath;
                press.ViewCount = 0;
                press.DateCreate = DateTime.Now.Date;
                press.UserNameCreate = User.Identity.Name;
                press.PressCategoryId = model.PressCategoryId;
                _repository.AddPress(press);
                return RedirectToAction("Index", new { message = "Đã tạo xong bài viết " + model.Title });
            }
            return View("~/Views/Admin/Press/Create.aspx", model);
        }
        //tao bai viet dich
        public ActionResult CreateTranslatedPress(int pressId)
        {
            //tao viewmodel cho ban dich
            Press_TranslatedCopy model = new Press_TranslatedCopy();
            model.PressId = pressId;
            model.Press = _repository.GetPress(pressId);
            return View("~/Views/Admin/Press/CreatePressTranslatedCopy.aspx", model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult CreateTranslatedPress(Press_TranslatedCopy model)
        {
            if (ModelState.IsValid)
            {
                Press_TranslatedCopy press = new Press_TranslatedCopy();
                press.PressId = model.PressId;
                press.Body = model.Body;
                press.Language = "en-Us";
                press.Title = model.Title;
                press.UserNameTranslated = User.Identity.Name;
                press.Description = model.Description;
                press.ViewCount = 0;
                _repository.AddPressTranslatedCopy(press);
                return RedirectToAction("Index", new { message = "Đã dịch xong bài viết " + model.Title });
            }
            return View("~/Views/Admin/Press/CreatePressTranslatedCopy.aspx", model);
            //tao dl cho ban dich   
        }
        //nho kiem tra nguoi viet va authorized
        public ActionResult EditPress(int pressId)
        {
            if (_repository.IsPressOwner(pressId, User.Identity.Name)||User.IsInRole("Admin")||User.IsInRole("Super Admin"))
            {
                PressCpo model = new PressCpo();
                var press = _repository.GetPress(pressId);
                model.Body = press.Body;
                model.ImagePath = press.ImagePath;
                model.Description = press.Description;
                model.Title = press.Title;
                model.PressCategoryId = press.PressCategoryId;
                model.PressCategories = _repository.PressCategories();
                model.ViewCount = press.ViewCount.Value;
                model.PressId = press.PressId;
                return View("~/Views/Admin/Press/Edit.aspx", model);
            }
            return RedirectToAction("Index", new { message = "Thông báo : Bạn không phải chủ nhân bài viết hoặc không đủ quyền nên không sửa được" });
        }
        [HttpPost]
        [ValidateInput((false))]
        public ActionResult EditPress(PressCpo model)
        {
            if (ModelState.IsValid)
            {
                string name = model.Title;
                name = name.Replace("?", "");
                name = name.Replace(".", "");
                name = name.Replace("/", "");
                name = name.Replace("\\", "");
                name = name.Replace("*", "");
                name = name.Replace("&", " và ");
                name = name.Replace("+", "-");
                Press press = new Press();
                press.Title = name;
                
               
                press.Body = model.Body;
                press.Description = model.Description;
                press.ImagePath = model.ImagePath;
                press.ViewCount = model.ViewCount;
                press.DateCreate = DateTime.Now;
                press.UserNameCreate = User.Identity.Name;
                press.PressCategoryId = model.PressCategoryId;
                press.PressId = model.PressId;
                _repository.EditPress(press);
                return RedirectToAction("Index", new { message = "Thông báo : Đã sửa xong bài viết " + press.Title });
            }
            return View("~/Views/Admin/Press/Edit.aspx", model);
        }
        public ActionResult DeletePress(int pressId)
        {
            if (_repository.IsPressOwner(pressId, User.Identity.Name) || User.IsInRole("Admin")||User.IsInRole("Super Admin"))
            {
                _repository.DelPress(pressId);
                return RedirectToAction("Index", new {message = "Đã xóa bài viết"});
            }
            else
            {
                return RedirectToAction("Index", new {message = "Bạn không đủ quyền xóa bài"});
            }
        }
        //sua bai dich
       //ten mac dinh la ThienChi
        public ActionResult EditTranslatedPress(int id)
        {


            if (_repository.IsPressTranslatedOwner(id, User.Identity.Name) || User.IsInRole("Admin") || User.IsInRole("Super Admin"))
            {
                Press_TranslatedCpo model = new Press_TranslatedCpo();
                Press_TranslatedCopy m = _repository.GetPressTranslated(id);
                model.Title = m.Title;
                model.Body = m.Body;
                model.Description = m.Description;
                model.Id = m.Id;
                return View("~/Views/Admin/Press/EditTranslatedPress.aspx",model);
            }
            return RedirectToAction("Index", new { message = "Bạn không đủ quyền sửa bài vì bạn không viết bài này hoặc không đủ quyền!" });
        }
        //post len bai dich de sua
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult EditTranslatedPress(Press_TranslatedCpo model)
        {
            //chuyen ve danh muc chua bai dich do
            Press_TranslatedCopy m = _repository.GetPressTranslated(model.Id);
            m.Title = model.Title;
            m.Description = model.Description;
            m.Body = model.Body;

            _repository.db.SaveChanges();
            int cid = m.Press.PressCategoryId;
            return RedirectToAction("ViewPressCategoriesDetails", new { pressCategoryId = cid });
        }
        public ActionResult DeleteTranslatedCopy(int id)
        {
            if(_repository.IsPressTranslatedOwner(id,User.Identity.Name) ||User.IsInRole("Admin") || User.IsInRole("Super Admin"))
            {
                _repository.DeletePressTranslatedCopy(id);
                return RedirectToAction("Index", new {mes = "Thông báo : Đã xóa bài dịch "});
            }
            return Content("Thông báo : Bạn không phải là người dịch hoặc không đủ quyền nên bạn không được xóa bài này !");
        }
        #endregion
        #region Quan tri thanh vien
       [Authorize(Roles="Super Admin,Admin")]
        public ActionResult CreateMember()
        {
            RegisterModel model = new RegisterModel();
            ViewData["PasswordLength"] = 6;
            return View("~/Views/Admin/Account/CreateMember.aspx");

        }
        [HttpPost]
        public ActionResult CreateMember(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.UserName, "nhân viên");
                    return RedirectToAction("MemberManager");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = 6;
            return View("~/Views/Admin/Account/CreateMember.aspx");
        }
        //[Authorize(Roles = "Super Admin, admin")]
       [Authorize(Roles = "Super Admin,Admin")]

        public ActionResult AddRole(string userName)
       {
           UserInRoles model = new UserInRoles();
           if (User.IsInRole("Super Admin"))
           {
               model.UserName = userName;
               model.Roles = Roles.GetAllRoles().ToList();
               model.Role = "";
               return View("~/Views/Admin/Member/AddRole.aspx", model);
           }
           else
           {
               model.UserName = userName;
               model.Roles = Roles.GetAllRoles().ToList();
               model.Roles.Remove("Super Admin");
               model.Role = "";
               return View("~/Views/Admin/Member/AddRole.aspx", model);
           }
       }
        [HttpPost]
        public ActionResult AddRole(UserInRoles model)
        {
            string role = model.Role;
            string userName = model.UserName;
            Roles.AddUserToRole(userName,role);
            return RedirectToAction("MemberManager");

        }
        public ActionResult DeleteMember(string userName)
        {

            _repository.DeleteMember(userName);
            return RedirectToAction("MemberManager");
        }
        // [Authorize(Roles = "Super Admin, admin")]
       [Authorize(Roles = "Super Admin,Admin")]

        public ActionResult AdminChangePasswordForMember(string userId)
        {

            AdminChangePasswordForMemberViewModel newmodel = new AdminChangePasswordForMemberViewModel();
            newmodel.UserId = userId;
            newmodel.Password = "";
            return View("~/Views/Admin/Account/AdminChangePasswordForMember.aspx", newmodel);

        }
        [HttpPost]
        public ActionResult AdminChangePasswordForMember(AdminChangePasswordForMemberViewModel model)
        {
            if (ModelState.IsValid && model.Password.Length >= 6)
            {
                var st = Membership.GetUser(model.UserId);
                st.ChangePassword(st.ResetPassword(), model.Password);
                return RedirectToAction("MemberManager");
            }
            else
            {
                return View("~/Views/Admin/Account/AdminChangePasswordForMember.aspx", model);


            }
        }
       [Authorize(Roles = "Super Admin,Admin")]
        public ActionResult MemberManager()
        {

            MembershipUserCollection model = Membership.GetAllUsers();

            return View("~/Views/Admin/Member/MemberManager.aspx", model);
        }
        //sua thong tin cua thanh vien
        #endregion
        #region Quan tri hinh anh
        public ActionResult EditImage(int id)
        {
            EditImageModel model = new EditImageModel();
            model.ID = id;
            IMAGE m = Repository.FindImageById(id);
            if (m.UserCreate.Trim() == User.Identity.Name||User.IsInRole("Admin")||User.IsInRole("Super Admin"))
            {

                model.ImageName = m.ImageName;
                model.Description = m.Description;
                model.DescriptionEnglish = m.DescriptionEnglish;
                model.ImageNameEnglish = m.ImageNameEngLish;
                return View("~/Views/Admin/AdminImg/EditImage.aspx", model);
            }
            
            return RedirectToAction("ImageManager",
                                    new
                                        {
                                            Message =
                                        "Thông báo : Bạn không sửa được ảnh này vì không đủ quyền hoặc không phải người gởi"
                                        });
            
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult EditImage(EditImageModel model)
        {
            IMAGE m = Repository.FindImageById(model.ID);
            if (model.ImageName == null) model.ImageName = "";
            if (model.ImageNameEnglish == null) model.ImageNameEnglish = "";
            

            m.ImageName = model.ImageName;
            m.ImageNameEngLish = model.ImageNameEnglish;
            m.Description = model.Description;
            m.DescriptionEnglish = model.DescriptionEnglish;
            Repository.Db.SaveChanges();
            return RedirectToAction("ImageManager",new{Message="Thông báo : Đã sửa thông tin ảnh xong "+m.ImageName});
        }
        [HttpGet]
        public ActionResult CreateAlbum()
        {
            var imgmodel = new AlbumModel();
            return View("~/Views/Admin/AdminImg/CreateAlbum.aspx", imgmodel);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult CreateAlbum(AlbumModel albumModel)
        {
            var album = new ALBUM()
            {
                AlbumName = albumModel.AlbumName,
                AlbumPath = albumModel.AlbumPath,
                Description = albumModel.Description,
                AlbumNameEnglish=albumModel.AlbumNameEnglish,
                DescriptionEnglish = albumModel.DescriptionEnglish
            };
            Repository.CreateNewAlbum(album);
            AlbumViewModel albumViewModel = new AlbumViewModel();
            albumViewModel.Album = album;
            //tao thu muc co ten la ten cua album
         
            var pathpri = "~/Content/StoredImages/" + albumModel.AlbumName;
            if (Directory.Exists(Server.MapPath(pathpri)))
            {
                albumViewModel.ErrorMessage = "Album này đã tồn tại !";
            }
            Directory.CreateDirectory(Server.MapPath(pathpri));
            var pathThumbFori = "~/Content/StoredImages/" + albumModel.AlbumName + "/Thumbs";
            Directory.CreateDirectory(Server.MapPath(pathThumbFori));
            var pathImageFori = "~/Content/StoredImages/" + albumModel.AlbumName + "/Images";
            Directory.CreateDirectory(Server.MapPath(pathImageFori));
            return RedirectToAction("ImageManager",new{mes="Thông báo : Đã tạo thành công album "+albumModel.AlbumName});
        }

        public ActionResult UploadImage()
        {



            var listalbum = Repository.FindAllAlbum();
            var imgfullmodel = new ImageFullModel() { ListAlbum = listalbum };
            imgfullmodel.Message = "Thông báo : Up ảnh lên cho website";
            return View("/Views/Admin/Adminimg/UploadImage.aspx", imgfullmodel);
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult UploadImage(string str, ImageFullModel imageFullModel)
        {
            if (ModelState.IsValid)
            {
                if (Request.Files != null)
                {
                    var posted = Request.Files["uploadFile"];
                    if (posted != null)
                        if (posted.FileName != "")
                        {
                            var img = new IMAGE();
                            //điểm yếu là phải gán albumid trước 
                            img.AlbumId = imageFullModel.AlbumId;
                            // tạo thư mục mới nếu tồn tại thì chưa làm dc
                            CreatFolder(Repository.FindAlbumNameById(img.AlbumId));

                            var pathStoredImage = string.Format("/Content/StoredImages/{0}/Images/", Repository.FindAlbumNameById(img.AlbumId));
                            var pathStoredThumbs = string.Format("/Content/StoredImages/{0}/Thumbs/", Repository.FindAlbumNameById(img.AlbumId));
                            var imageName = Path.GetFileName(posted.FileName);
                            var filePath = pathStoredImage + imageName;
                            posted.SaveAs(Server.MapPath(filePath));
                            //luu vao csdl
                            img.ImageName = imageFullModel.ImageName;

                            img.ImagePath = pathStoredImage + imageName;
                            img.ImageThumbPath = pathStoredThumbs + imageName;
                            img.UserCreate =User.Identity.Name;//nho phai doi
                            img.IsSlide = false;
                            img.CreateDay = DateTime.Now.Date;
                            img.IsSlide = false;
                            ResizeImage(img, 180);
                            img.Description = imageFullModel.Description;
                            img.ImageNameEngLish = imageFullModel.ImageNameEnglish;
                            img.DescriptionEnglish = imageFullModel.DescriptionEnglish;
                            Repository.DB.IMAGEs.AddObject(img);
                            Repository.DB.SaveChanges();
                              return RedirectToAction("DetailsAlbum", new { id =img.AlbumId,currentPage=1});
                        }
                }
              

            }
            imageFullModel.ListAlbum = Repository.FindAllAlbum();
            return View("~/Views/Admin/AdminImg/UploadImage.aspx", imageFullModel);
        }
        public void CreatFolder(string albumName)
        {
            var pathpri = "~/Content/StoredImages/" + albumName;
            if (!Directory.Exists(Server.MapPath(pathpri)))
            {
                Directory.CreateDirectory(Server.MapPath(pathpri));
                var pathThumbFori = "~/Content/StoredImages/" + albumName + "/Thumbs";
                Directory.CreateDirectory(Server.MapPath(pathThumbFori));
                var pathImageFori = "~/Content/StoredImages/" + albumName + "/Images";
                Directory.CreateDirectory(Server.MapPath(pathImageFori));
            }
        }
        //[HttpPost]
        //public ActionResult Upload()
        //{
        //    foreach (string inputTagName in Request.Files)
        //    {
        //        HttpPostedFileBase file = Request.Files[inputTagName];
        //        if (file.ContentLength > 0)
        //        {
        //            string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.FileName));
        //            file.SaveAs(filePath);
        //        }
        //    }

        //    return RedirectToAction("Index");
        //}
        public void ResizeImage(IMAGE img, int imageSize)
        {
            var newImage = new Bitmap(Server.MapPath(img.ImagePath));
            var thumbnailSize = imageSize;
            int newWidth, newHeight;

            if (newImage.Width > newImage.Height)
            {
                newWidth = thumbnailSize;
                newHeight = newImage.Height * thumbnailSize / newImage.Width;
            }
            else
            {
                newWidth = newImage.Width * thumbnailSize / newImage.Height;
                newHeight = thumbnailSize;
            }

            var thumbnailBitmap = new Bitmap(newWidth, newHeight);
            // không hiểu mấy cái ni luôn huhu
            var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
            thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbnailGraph.DrawImage(newImage, imageRectangle);
            var path1 = string.Format("/StoredImages/{0}/Images/", Repository.FindAlbumNameById(img.AlbumId));
            var path2 = string.Format("/StoredImages/{0}/Thumbs/", Repository.FindAlbumNameById(img.AlbumId));

            img.ImageThumbPath = img.ImagePath.Replace(path1, path2);
            thumbnailBitmap.Save(Server.MapPath(img.ImageThumbPath));
            thumbnailGraph.Dispose();
            thumbnailBitmap.Dispose();
            newImage.Dispose();
        }

        // xem chi tiet file anh

        public ActionResult DetailsAlbum(int id,int? currentPage)
        {
            ImagesViewsModel model = new ImagesViewsModel();
            if(currentPage.HasValue)
            { 
                model.ListImages = Repository.ImagesInAlbum(id, int.Parse(currentPage.Value.ToString()) - 1);
                model.CurrentPage = currentPage.Value;
                model.TotalItem = Repository.Db.ALBUMs.Where(m => m.ID == id).FirstOrDefault().IMAGEs.Count;
            }
            else
            {
                 model.ListImages = Repository.ImagesInAlbum(id, 0);
                model.CurrentPage = 1;
                 model.TotalItem = Repository.Db.ALBUMs.Where(m => m.ID == id).FirstOrDefault().IMAGEs.Count;
            }
            model.ListAlbum = Repository.FindAllAlbum();
            return View("~/Views/Admin/AdminImg/DetailsAlbum.aspx", model);
        }
        [HttpGet]
        //public ActionResult EditAlbum(int id)
        //{
        //    return View(Repository.FindAlbumById(id));
        //}
        //[HttpPost]
        //public ActionResult EditAlbum(int id, FormCollection formCollection)
        //{
        //    var a = Repository.FindAlbumById(id);
        //    UpdateModel(a);
        //    Repository.CommitChange();
        //    return RedirectToAction("Index", "Home");
        //}
        public ActionResult SetSlide(int id)
        {
            Repository.SetSlide(id);
            return RedirectToAction("ImageManager", new { mes = "Thông báo : Đã đặt ảnh có mã số là " + id + " làm ảnh slide" });
        }
        public ActionResult UnSetSlide(int id)
        {
            Repository.UnSetSlide(id);
            return RedirectToAction("ImageManager", new { mes = "Thông báo : Đã hủy ảnh có mã số là " + id + " làm ảnh slide" });
        }
        public ActionResult ImageManager(string mes)
        {
            ImageFullModel model = new ImageFullModel();
            model.ListAlbum = Repository.FindAllAlbum();
            model.ListImage = Repository.ViewImage(10);
            if (string.IsNullOrEmpty(mes))
                model.Message = "Thông báo : Trang chủ quản trị các hình ảnh của website";
            else
            {
                model.Message = mes;
            }
            return View("~/Views/Admin/AdminImg/ImageManager.aspx", model);
        }
        public ActionResult DeleteImages(int id)
        {
            IMAGE m = Repository.FindImageById(id);
            string st = Server.MapPath(m.ImagePath);
            string st2 = Server.MapPath(m.ImageThumbPath);
            System.IO.File.Delete(st);
            System.IO.File.Delete(st2);
            Repository.DeleteImage(id);
            return RedirectToAction("ImageManager", new {mes = "Đã xóa ảnh"});
        }
        #endregion
    }
}
